const router = require('koa-router')() //引入路由函数
/**
 * ==============================================定义model的=================================
 * */ 
/**
 * @swagger
 * definitions:
 *   user:
 *     properties:
 *       name:
 *         type: string
 *       breed:
 *         type: string
 *       age:
 *         type: integer
 *       sex:
 *         type: string
 */
router.get('/', async (ctx, next) => {
  'use strict'
  ctx.redirect('/user/login')
})
// 路由中间件，页面路由到／，就是端口号的时候，（网址），页面指引到 /user/login
/**
 * @swagger
 * /user/info:
 *   get:
 *     tags:
 *       - 用户
 *     description: Returns all user
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: id
 *         description: 用户id
 *         in: query
 *         required: true
 *       - name: gender
 *         description: 用户性别
 *         in: query
 *         required: true
 *     responses:
 *       200:
 *         description: An array of user
 *         schema:
 *           $ref: '#/definitions/user'
 */
router.get('/user/info', async (ctx, next) => {
  ctx.body = "asdasd"
})
/**
 * @swagger
 * /api/logout:
 *   post:
 *     tags:
 *       - 权限
 *     description: Creates a new puppy
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: puppy
 *         description: Puppy object
 *         in: body
 *         required: true
 *         schema:
 *           $ref: '#/definitions/user'
 *     responses:
 *       200:
 *         description: Successfully created
 */
router.post('/user/logout', async (ctx, next) => {
  ctx.body = "asdasd"
})
/**
 * @swagger
 * /api/login:
 *   post:
 *     tags:
 *       - 权限
 *     description: Creates a new login
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: user
 *         description: user object
 *         in: body
 *         required: true
 *         schema:
 *           $ref: '#/definitions/user'
 *     responses:
 *       200:
 *         description: Successfully created
 */
router.post('/user/login', async (ctx, next) => {
  ctx.body = "asdasd"
})


/**
 * @swagger
 * /user/test/{id}:
 *   get:
 *     tags:
 *       - 用户
 *     description: 用户信息测试
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: id
 *         description: 用户id
 *         in: path
 *         required: true
 *     responses:
 *       200:
 *         description: Successfully created
 */
router.get('/user/test/:id', async (ctx, next) => {
  ctx.body = "asdasd"
})

/**
 * @swagger
 * /user/test1:
 *   get:
 *     tags:
 *       - 用户
 *     description: 用户信息测试
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: id
 *         description: 用户id
 *         in: header
 *         required: true
 *     responses:
 *       200:
 *         description: Successfully created
 */
router.get('/user/test1', async (ctx, next) => {
  console.log(ctx.request.header.id)
  ctx.body = {
    name: 'asdasd',
    password: '111111'
  }
})

/**
 * @swagger
 * /user/test2:
 *   post:
 *     tags:
 *       - 用户
 *     description: 用户信息测试
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: id
 *         description: 用户id
 *         in: formData
 *         required: true
 *         type: String
 *     responses:
 *       200:
 *         description: Successfully created
 */
router.post('/user/test2', async (ctx, next) => {
  console.log(ctx)
  ctx.body = {
    name: 'asdasd',
    password: '111111'
  }
})

//将页面暴露出去
module.exports = router